package com.yeung.controller;

import com.yeung.beans.User;
import com.yeung.dao.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserJpaController {
    @Autowired
    UserRepository userRepository;

    @GetMapping("/jpa/user/{id}")
    public User getUser(@PathVariable("id") Integer id) {
        User one = userRepository.getOne(id);
        return one;
    }

    @GetMapping("/jpa/user")
    public User insertUser(User user) {
        User save = userRepository.save(user);
        return save;
    }

}
